package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.danmo.domain.DanmoCity;
import com.muyu.danmo.service.IDanmoCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 城市Controller
 *
 * @author yangle
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/city")
public class DanmoCityController extends BaseController
{
    @Autowired
    private IDanmoCityService danmoCityService;

    /**
     * 查询城市列表
     */
//    @RequiresPermissions("system:city:list")
    @GetMapping("/list")
    public Result list(DanmoCity danmoCity)
    {
        List<DanmoCity> list = danmoCityService.selectDanmoCityList(danmoCity);
        return Result.success(list);
    }

    /**
     * 导出城市列表
     */
    @RequiresPermissions("system:city:export")
    @Log(title = "城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoCity danmoCity)
    {
        List<DanmoCity> list = danmoCityService.selectDanmoCityList(danmoCity);
        ExcelUtil<DanmoCity> util = new ExcelUtil<DanmoCity>(DanmoCity.class);
        util.exportExcel(response, list, "城市数据");
    }

    /**
     * 获取城市详细信息
     */
    @RequiresPermissions("system:city:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoCityService.selectDanmoCityById(id));
    }

    /**
     * 新增城市
     */
    @RequiresPermissions("system:city:add")
    @Log(title = "城市", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoCity danmoCity)
    {
        return toAjax(danmoCityService.insertDanmoCity(danmoCity));
    }

    /**
     * 修改城市
     */
    @RequiresPermissions("system:city:edit")
    @Log(title = "城市", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoCity danmoCity)
    {
        return toAjax(danmoCityService.updateDanmoCity(danmoCity));
    }

    /**
     * 删除城市
     */
    @RequiresPermissions("system:city:remove")
    @Log(title = "城市", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoCityService.deleteDanmoCityByIds(ids));
    }
}
